import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:paly_android/api/api.dart';
import 'package:paly_android/bean/article_data_entity.dart';
import 'package:paly_android/net/dio_client.dart';

class ArticleBloc extends Cubit<ArticleDataEntity> {
  ArticleBloc() : super(ArticleDataEntity.emtpty());

  void getArticles(bool isRefresh, int page) {
    DioClient.instance
        .get(Api.ARTICLE_LIST.replaceFirst("page", page.toString()),
            onSuccess: (ArticleDataEntity entity) {
      if (!isRefresh) {
        entity.datas.insertAll(0,  state.datas);
      }
      emit(entity);


    });
  }
}
